package com.ctosb.classviewer.clazz.attr;

import com.ctosb.classviewer.ClassReader;
import com.ctosb.classviewer.clazz.cp.CONSTANT_Class_info;
import com.ctosb.classviewer.clazz.cp.CONSTANT_NameAndType_info;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class EnclosingMethod_attribute extends Attribute_info {

    private short class_index;
    private short method_index;

    @Override
    protected void doParse(ClassReader classReader) {
        class_index = classReader.readShort();
        method_index = classReader.readShort();
    }

    /**
     * 获取class信息
     * @Author alan
     * @Date 2020/12/16 12:15 上午
     * @return
     */
    public CONSTANT_Class_info getClassInfo() {
        return (CONSTANT_Class_info) getClassFile().getConstant_pool()[class_index];
    }

    /**
     * 获取方法信息
     * @Author alan
     * @Date 2020/12/16 12:16 上午
     * @return
     */
    public CONSTANT_NameAndType_info getMethod() {
        if (method_index == 0) {
            return null;
        }
        return (CONSTANT_NameAndType_info) getClassFile().getConstant_pool()[method_index];
    }
}
